package com.itheima.reggie.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.reggie.dao.EmployeeDao;
import com.itheima.reggie.pojo.Employee;
import com.itheima.reggie.pojo.Page;
import com.itheima.reggie.service.EmployeeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class EmployeeServiceImpl implements EmployeeService {
    @Autowired
    private EmployeeDao employeeDao;

    @Override
    public Page<Employee> findByPage(Integer pageNum, Integer pageSize, String name) {
        List<Employee> list = employeeDao.findByName(name);
       return new Page<>(list);
    }

    @Override
    public void save(Employee employee) {
        //对比密码
        BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
        employee.setPassword(encoder.encode("123456"));
        //2. 设置用户状态为1
        employee.setStatus(1);
        //4. 调用数据访问层插入数据
        employeeDao.save(employee);
    }


    @Override
    public void update(Employee employee) {
        //调用业务层更新
        employeeDao.update(employee);
    }

    @Override
    public Employee findById(Long id) {
        return employeeDao.findById(id);
    }
}
